import request from '@/utils/request'
import type { RoleListResponse, RoleItem, BaseResponse, RoleMenuListResponse } from '@/types'

// 获取所有角色
export const getAllRolesAPI = (): Promise<RoleListResponse> => {
  return request.get('/api/SysRole/GetAll')
}

// 添加角色
export const addRoleAPI = (data: RoleItem): Promise<BaseResponse> => {
  return request.post('/api/SysRole/Insert', data)
}

// 修改角色
export const updateRoleAPI = (data: RoleItem): Promise<BaseResponse> => {
  return request.post('/api/SysRole/Update', data)
}

// 删除角色
export const deleteRoleAPI = (id: string): Promise<BaseResponse> => {
  return request.post('/api/SysRole/DelteByIds', [id])
}

// 根据ID查询角色
export const getRoleByIdAPI = (id: string): Promise<BaseResponse> => {
  return request.get('/api/SysRole/GetById', { params: { id } })
}

// 绑定菜单（菜单权限）
export const bindMenuAPI = (data: { roleId: string; menuIds: string[] }): Promise<BaseResponse> => {
  console.log(data)
  return request.post('/api/SysRole/BindMenus', data)

}
// 查询角色绑定的菜单列表
export const getRoleMenuListAPI = (roleId: string): Promise<RoleMenuListResponse> => {
  return request.get('/api/SysMenu/GetRoleMenuList', { params: { roleId } })
}

// 查询角色绑定的菜单
export const getUserRoleListAPI = <T>(userId: string): Promise<BaseResponse<T>> => {
  return request.get('/api/SysRole/GetUserRoleList', { params: { userId } })
}

